import table from '@/components/form/table';
import SubTable from '@/components/form/SubTable';
import textInput from '@/components/form/textInput';
import numberInput from '@/components/form/numberInput';
import enumInput from '@/components/form/enumInput';
import dateInput from '@/components/form/dateInput';
import radioInput from '@/components/form/radioInput';
import timeInput from '@/components/form/timeInput';
import checkInput from '@/components/form/checkInput';
import attachInput from '@/components/form/attachInput';
import userInput from '@/components/form/userInput';
import departInput from '@/components/form/departInput';
import unitInput from '@/components/form/unitInput';
import textAreaInput from '@/components/form/textAreaInput';

const inputs = {
  layouts: [table, SubTable],
  formComponents: [textInput, numberInput, enumInput, dateInput, radioInput, timeInput, checkInput, attachInput, textAreaInput, userInput, departInput, unitInput],
  getComponent(name) {
    name = name.toLowerCase();
    for (let i = 0; i < this.layouts.length; i++) {
      if (this.layouts[i].name.toLowerCase() === name) {
        return this.layouts[i];
      }
    }

    for (let i = 0; i < this.formComponents.length; i++) {
      if (this.formComponents[i].name.toLowerCase() === name) {
        return this.formComponents[i];
      }
    }
  },
};

export default inputs;


export function resolveFieldTypeByComponentName(componentName) {
  let comp = inputs.getComponent(componentName);
  if (comp && comp.resolveFieldType) {
    return comp.resolveFieldType();
  }
  return 'string';
}
